//
//  ViewController.m
//  JKRuntimeMethod_exchange
//
//  Created by 王冲 on 2018/10/10.
//  Copyright © 2018年 JK科技有限公司. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    UILabel *label;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    // 1 UIButton 点击方法的交换
    //[self buttonExchangeSelector];
    // 2 可变数组添加的交换
    //[self nsMutableArrayExchange];
    // 3 可变字典添加的交换
    //[self nsMutableDictionaryExchange];
    // 4.字体大小的修改
    [self font];
    
    
}

#pragma mark 字体大小的修改
-(void)font{
    
    UserDefaultSetValue(@"1",@"JKFont");
    Synchronize;
    
    label = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, [UIScreen mainScreen].bounds.size.width-40, 100)];
    label.backgroundColor = [UIColor yellowColor];
    label.text = @"我爱中国";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor purpleColor];
    label.font = [UIFont systemFontOfSize:10.f];
    [self.view addSubview:label];
    
    for (int i = 0; i<3; i++) {
        
        UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(20, 240+i*(60+20), 100, 60)];
        button1.tag = i +101;
        [button1 setTitle:[NSString stringWithFormat:@"%d倍",i+1] forState:UIControlStateNormal];
        [button1 setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
        [button1 setBackgroundColor:[UIColor brownColor]];
        button1.titleLabel.font = [UIFont systemFontOfSize:15.f];
        [button1 addTarget:self action:@selector(clickFont:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button1];
    }
    
    
}

#pragma mark 修改字体的大小
-(void)clickFont:(UIButton *)sender{
    
    NSString *fonStr = [NSString stringWithFormat:@"%ld",sender.tag-100];
    UserDefaultSetValue(fonStr,@"JKFont");
    Synchronize;
    
    // 重新设置UIButton的字体大小
    sender.titleLabel.font = [UIFont systemFontOfSize:15.f];
    
    // 重新设置label的字体大小
    label.font = [UIFont systemFontOfSize:10.f];
}

#pragma mark 3 可变字典添加的交换
-(void)nsMutableDictionaryExchange{
    
    NSString *obj = nil;
    
    /*
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    dict[@"name"] = @"JK";
    dict[obj] = @"HH";
     */
    
    NSDictionary *dic = @{@"a":@"1",@"b":@"2"};
    
    NSString *value = dic[obj];
    
    //NSLog(@"%@",[dic class]);
    
    
    
    
  
}

#pragma mark 2 可变数组添加的交换
-(void)nsMutableArrayExchange{
    
    NSString *obj = nil;
   
    NSMutableArray *array = [NSMutableArray array];
    [array addObject:@"jack"];
    
    // 插入或者说添加空的值也不会崩溃了
    [array insertObject:obj atIndex:0];
    
    NSLog(@"%@",array);
    
}

#pragma mark 1 UIButton 点击方法的交换
-(void)buttonExchangeSelector{
    
    UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(20, 100, 100, 60)];
    [button1 setTitle:@"按钮1" forState:UIControlStateNormal];
    [button1 setBackgroundColor:[UIColor brownColor]];
    [button1 addTarget:self action:@selector(click1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(button1.frame)+60, 100, 60)];
    [button2 setTitle:@"按钮2" forState:UIControlStateNormal];
    [button2 setBackgroundColor:[UIColor brownColor]];
    [button2 addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(button2.frame)+60, 100, 60)];
    [button3 setTitle:@"按钮3" forState:UIControlStateNormal];
    [button3 setBackgroundColor:[UIColor brownColor]];
    [button3 addTarget:self action:@selector(click3) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button3];
}

-(void)click1{
    
    NSLog(@"%s",__func__);
}

-(void)click2{
    
    NSLog(@"%s",__func__);
}

-(void)click3{
    
    NSLog(@"%s",__func__);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
